const express = require("express");
const router = express.Router();
// 导入验证数据的中间件
const expressJoi = require("@escook/express-joi");

var multipart = require('connect-multiparty');
// 导入formdata数据的中间件
var multipartMiddleware = multipart();
// 导入路由处理函数模块
const {getArtcate,addArtcate,delArtcateById,getArtcateById,updateArtcateById,downLoadImg,delArtcatesById} = require("../rooterhandler/artcate");
const {addCatesSchema,delCatesSchema,getCatesSchema,updateCatesSchema,delsCatesSchema} = require("../schema/artcate")
// 获取文章分类
router.get("/getcates",getArtcate)
// 新增文章分类列表
router.post("/addcates",expressJoi(addCatesSchema),addArtcate)
// 删除单个文章分类
router.get("/deletecate/:id",expressJoi(delCatesSchema),delArtcateById)

// 多个删除 有根 批量删除 传递json 数组
router.post("/deletecates",multipartMiddleware,expressJoi(delsCatesSchema),delArtcatesById)
// 获取文章分类详情
router.get("/cates/:id",expressJoi(getCatesSchema),getArtcateById)
// 根据id更新文章分类数据
router.post("/updatecate",expressJoi(updateCatesSchema),updateArtcateById)

// 下载图片
router.get("/download",downLoadImg)
module.exports = router;